import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    FixWorkerListViewState state, Dispatch dispatch, ViewService viewService) {
  Widget _buildListItem(int index) {
    FixWorkerModel mModel = state.workers[index];

    return MyInkWellWidget(
      child: Container(
        height: 55,
        margin: EdgeInsets.only(left: 20, right: 20),
        child: Row(
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    mModel.userName,
                    style: TextThemeConfig.Font15WithColor22,
                  ),
                  MyInkWellWidget(
                    child: Text(
                      mModel.userPhone,
                      style: TextThemeConfig.Font14WithMainColor,
                    ),
                    onTap: () => CommonUtils.callPhone(
                        mModel.userPhone, viewService.context),
                  )
                ],
              ),
            ),
            Image.asset((state.currentWorker != null &&
                    state.currentWorker.userID == mModel.userID)
                ? 'images/cricle_select.png'
                : 'images/circle.png'),
          ],
        ),
        decoration: BoxDecoration(
          border: Border(bottom: BorderSide(color: ThemeConfig.separeColor)),
          color: Colors.white,
        ),
      ),
      onTap: () => dispatch(FixWorkerListViewActionCreator.onTapIndex(mModel)),
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '选择接单工作人员'),
    backgroundColor: Colors.white,
    body: state.workers == null
        ? MyLoadingWidget()
        : Column(
            children: [
              Expanded(
                child: CustomRefreshList(
                  child: ListView.builder(
                    itemBuilder: (BuildContext context, int index) {
                      return _buildListItem(index);
                    },
                    itemCount: state.workers.length,
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                  ),
                  refreshController: state.refreshController,
                  onRefresh: (_) =>
                      dispatch(FixWorkerListViewActionCreator.onLoad()),
                  currentPage: 1,
                ),
              ),
              SafeArea(
                child: Container(
                  width: double.infinity,
                  margin: EdgeInsets.only(left: 20, right: 20, bottom: 30),
                  height: 50,
                  decoration: BoxDecoration(
                    color: ThemeConfig.mainColor,
                    borderRadius: BorderRadius.all(Radius.circular(4)),
                  ),
                  child: InkWell(
                    child: Center(
                      child: Text(
                        '确定',
                        style: TextThemeConfig.Font16WithWhite,
                      ),
                    ),
                    onTap: () =>
                        Navigator.pop(viewService.context, state.currentWorker),
                  ),
                ),
              ),
            ],
          ),
  );
}
